#include "GroupLib.h"

using namespace std;

/// <summary> 
/// Constructor 
/// </summary>
CICore::GroupLib::GroupLib() {}

/// <summary> 
/// Destructor 
/// </summary>
CICore::GroupLib::~GroupLib() {
    //Deleting all groups
    map<const char*, Group*>::iterator it = groups.begin();

    while (it != groups.end())
        delete ((it++)->second);
}








///<************************************************************************************************************>
///<**************************************** region Utility Methods ********************************************>
///<************************************************************************************************************>

/// <summary>
/// Method called to add a group in the library
/// </summary>
/// <param name="m"> The group to be added </param>
/// <returns> A bool to indicate if the the group has been added </returns>
bool CICore::GroupLib::Add (CICore::Group *m) {
    if (groups[m->name.c_str()] != 0)    //If already exists a group with the same name
        return false;                    //must return false

    groups[m->name.c_str()] = m;         //Adds the new group         
    return true;
}

/// <summary>
/// Method called to get a group from the library
/// </summary>
/// <param name="groupName"> The group name </param>
/// <returns> The group identified by groupName </returns>
CICore::Group* CICore::GroupLib::Get (const char* groupName) {
    return groups[groupName];
}

/// <summary>
/// Method called to remove a group from the library
/// </summary>
/// <param name="groupName"> The group name </param>
void CICore::GroupLib::Remove (const char* groupName) {
    groups.erase (groupName);
}
/***************************************************************************************************************
******************************************* endregion Utility Methods ******************************************
****************************************************************************************************************/

